In [16]:
!jupyter nbconvert --to notebook --clear-output --ClearMetadataPreprocessor.enabled=True --inplace CLIP Image- Text Similarity.ipynb
[NbConvertApp] WARNING | pattern 'CLIP' matched no files [NbConvertApp] WARNING | pattern 'Image-' matched no files [NbConvertApp] WARNING | pattern 'Text' matched no files [NbConvertApp] WARNING | pattern 'Similarity.ipynb' matched no files This application is used to convert notebook files (*.ipynb) to various other formats. WARNING: THE COMMANDLINE INTERFACE MAY CHANGE IN FUTURE RELEASES. Options ======= The options below are convenience aliases to configurable class-options, as listed in the "Equivalent to" description-line of the aliases. To see all configurable class-options for some <cmd>, use: <cmd> --help-all --debug set log level to logging.DEBUG (maximize logging output) Equivalent to: [--Application.log_level=10] --show-config Show the application's configuration (human-readable format) Equivalent to: [--Application.show_config=True] --show-config-json Show the application's configuration (json format) Equivalent to: [--Application.show_config_json=True] --generate-config generate default config file Equivalent to: [--JupyterApp.generate_config=True] -y Answer yes to any questions instead of prompting. Equivalent to: [--JupyterApp.answer_yes=True] --execute Execute the notebook prior to export. Equivalent to: [--ExecutePreprocessor.enabled=True] --allow-errors Continue notebook execution even if one of the cells throws an error and include the error message in the cell output (the default behaviour is to abort conversion). This flag is only relevant if '--execute' was specified, too. Equivalent to: [--ExecutePreprocessor.allow_errors=True] --stdin read a single notebook file from stdin. Write the resulting notebook with default basename 'notebook.*' Equivalent to: [--NbConvertApp.from_stdin=True] --stdout Write notebook output to stdout instead of files. Equivalent to: [--NbConvertApp.writer_class=StdoutWriter] --inplace Run nbconvert in place, overwriting the existing notebook (only relevant when converting to notebook format) Equivalent to: [--NbConvertApp.use_output_suffix=False --NbConvertApp.export_format=notebook --FilesWriter.build_directory=] --clear-output Clear output of current file and save in place, overwriting the existing notebook. Equivalent to: [--NbConvertApp.use_output_suffix=False --NbConvertApp.export_format=notebook --FilesWriter.build_directory= --ClearOutputPreprocessor.enabled=True] --coalesce-streams Coalesce consecutive stdout and stderr outputs into one stream (within each cell). Equivalent to: [--NbConvertApp.use_output_suffix=False --NbConvertApp.export_format=notebook --FilesWriter.build_directory= --CoalesceStreamsPreprocessor.enabled=True] --no-prompt Exclude input and output prompts from converted document. Equivalent to: [--TemplateExporter.exclude_input_prompt=True --TemplateExporter.exclude_output_prompt=True] --no-input Exclude input cells and output prompts from converted document. This mode is ideal for generating code-free reports. Equivalent to: [--TemplateExporter.exclude_output_prompt=True --TemplateExporter.exclude_input=True --TemplateExporter.exclude_input_prompt=True] --allow-chromium-download Whether to allow downloading chromium if no suitable version is found on the system. Equivalent to: [--WebPDFExporter.allow_chromium_download=True] --disable-chromium-sandbox Disable chromium security sandbox when converting to PDF.. Equivalent to: [--WebPDFExporter.disable_sandbox=True] --show-input Shows code input. This flag is only useful for dejavu users. Equivalent to: [--TemplateExporter.exclude_input=False] --embed-images Embed the images as base64 dataurls in the output. This flag is only useful for the HTML/WebPDF/Slides exports. Equivalent to: [--HTMLExporter.embed_images=True] --sanitize-html Whether the HTML in Markdown cells and cell outputs should be sanitized.. Equivalent to: [--HTMLExporter.sanitize_html=True] --log-level=<Enum> Set the log level by value or name. Choices: any of [0, 10, 20, 30, 40, 50, 'DEBUG', 'INFO', 'WARN', 'ERROR', 'CRITICAL'] Default: 30 Equivalent to: [--Application.log_level] --config=<Unicode> Full path of a config file. Default: '' Equivalent to: [--JupyterApp.config_file] --to=<Unicode> The export format to be used, either one of the built-in formats ['asciidoc', 'custom', 'html', 'latex', 'markdown', 'notebook', 'pdf', 'python', 'qtpdf', 'qtpng', 'rst', 'script', 'slides', 'webpdf'] or a dotted object name that represents the import path for an ``Exporter`` class Default: '' Equivalent to: [--NbConvertApp.export_format] --template=<Unicode> Name of the template to use Default: '' Equivalent to: [--TemplateExporter.template_name] --template-file=<Unicode> Name of the template file to use Default: None Equivalent to: [--TemplateExporter.template_file] --theme=<Unicode> Template specific theme(e.g. the name of a JupyterLab CSS theme distributed as prebuilt extension for the lab template) Default: 'light' Equivalent to: [--HTMLExporter.theme] --sanitize_html=<Bool> Whether the HTML in Markdown cells and cell outputs should be sanitized.This should be set to True by nbviewer or similar tools. Default: False Equivalent to: [--HTMLExporter.sanitize_html] --writer=<DottedObjectName> Writer class used to write the results of the conversion Default: 'FilesWriter' Equivalent to: [--NbConvertApp.writer_class] --post=<DottedOrNone> PostProcessor class used to write the results of the conversion Default: '' Equivalent to: [--NbConvertApp.postprocessor_class] --output=<Unicode> Overwrite base name use for output files. Supports pattern replacements '{notebook_name}'. Default: '{notebook_name}' Equivalent to: [--NbConvertApp.output_base] --output-dir=<Unicode> Directory to write output(s) to. Defaults to output to the directory of each notebook. To recover previous default behaviour (outputting to the current working directory) use . as the flag value. Default: '' Equivalent to: [--FilesWriter.build_directory] --reveal-prefix=<Unicode> The URL prefix for reveal.js (version 3.x). This defaults to the reveal CDN, but can be any url pointing to a copy of reveal.js. For speaker notes to work, this must be a relative path to a local copy of reveal.js: e.g., "reveal.js". If a relative path is given, it must be a subdirectory of the current directory (from which the server is run). See the usage documentation (https://nbconvert.readthedocs.io/en/latest/usage.html#reveal-js-html-slideshow) for more details. Default: '' Equivalent to: [--SlidesExporter.reveal_url_prefix] --nbformat=<Enum> The nbformat version to write. Use this to downgrade notebooks. Choices: any of [1, 2, 3, 4] Default: 4 Equivalent to: [--NotebookExporter.nbformat_version] Examples -------- The simplest way to use nbconvert is > jupyter nbconvert mynotebook.ipynb --to html Options include ['asciidoc', 'custom', 'html', 'latex', 'markdown', 'notebook', 'pdf', 'python', 'qtpdf', 'qtpng', 'rst', 'script', 'slides', 'webpdf']. > jupyter nbconvert --to latex mynotebook.ipynb Both HTML and LaTeX support multiple output templates. LaTeX includes 'base', 'article' and 'report'. HTML includes 'basic', 'lab' and 'classic'. You can specify the flavor of the format used. > jupyter nbconvert --to html --template lab mynotebook.ipynb You can also pipe the output to stdout, rather than a file > jupyter nbconvert mynotebook.ipynb --stdout PDF is generated via latex > jupyter nbconvert mynotebook.ipynb --to pdf You can get (and serve) a Reveal.js-powered slideshow > jupyter nbconvert myslides.ipynb --to slides --post serve Multiple notebooks can be given at the command line in a couple of different ways: > jupyter nbconvert notebook*.ipynb > jupyter nbconvert notebook1.ipynb notebook2.ipynb or you can specify the notebooks list in a config file, containing:: c.NbConvertApp.notebooks = ["my_notebook.ipynb"] > jupyter nbconvert --config mycfg.py To see all available configurables, use `--help-all`.
In [1]:
from sentence_transformers import SentenceTransformer
from PIL import Image
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline
import warnings
warnings.filterwarnings('ignore')

model = SentenceTransformer("clip-ViT-B-32")
Warning: You are sending unauthenticated requests to the HF Hub. Please set a HF_TOKEN to enable higher rate limits and faster downloads. WARNING:huggingface_hub.utils._http:Warning: You are sending unauthenticated requests to the HF Hub. Please set a HF_TOKEN to enable higher rate limits and faster downloads.
Loading weights:   0%|          | 0/398 [00:00<?, ?it/s]
CLIPModel LOAD REPORT from: /root/.cache/huggingface/hub/models--sentence-transformers--clip-ViT-B-32/snapshots/327ab6726d33c0e22f920c83f2ff9e4bd38ca37f/0_CLIPModel Key | Status | | -------------------------------------+------------+--+- text_model.embeddings.position_ids | UNEXPECTED | | vision_model.embeddings.position_ids | UNEXPECTED | | Notes: - UNEXPECTED :can be ignored when loading from different task/architecture; not ok if you expect identical arch. The image processor of type `CLIPImageProcessor` is now loaded as a fast processor by default, even if the model checkpoint was saved with a slow processor. This is a breaking change and may produce slightly different outputs. To continue using the slow processor, instantiate this class with `use_fast=False`.
In [2]:
project ="/content/drive/MyDrive/project/Screenshot 2026-02-08 143536.png"
Image.open(project)
Out[2]:
Output
In [3]:
image_path="/content/drive/MyDrive/project/cycling on road.jpg"
image1 = Image.open(image_path)
In [4]:
# Display the image
plt.figure(figsize=(10,10))           # make it larger
plt.imshow(image1)                    # display the image data
plt.axis('off')                       # hide axis
plt.title("Image for similarity comparision",fontsize=20)
plt.show()
Output
In [5]:
# YOUR DATA
text_description =[
    "Car parked near the building",
    "A person riding a bicycle on the road",
    "A man cycling on the road during sunset",
    "people sitting on the bicycles",
    "some persons riding a bicyle at the forest",
    "Motorcycle racing on track"
]
In [6]:
def display_image_and_compare(image_path,text_description):
  # Load the image
  img = Image.open(image_path)

  # Encode text descriptions and image
  text_emb = model.encode(text_description)
  img_emb = model.encode(img)

  # Compute similarity scores
  similarity_score =np.dot(text_emb,img_emb.T)

  # Find the match
  best_match_idx = np.argmax(similarity_score)
  best_match_desc = text_description[best_match_idx]

  # Print best match info
  print(f"\n best match for the image is : {best_match_desc} with the score of {similarity_score[best_match_idx]:.4f}" )
  # Display the image
  plt.figure(figsize=(10,10))           # make it larger
  plt.imshow(img)                    # display the image data
  plt.axis('off')                       # hide axis
  plt.title("Image for similarity comparision",fontsize=20)
  plt.show()
In [7]:
display_image_and_compare(image_path,text_description)
best match for the image is : A person riding a bicycle on the road with the score of 26.8143
Output
In [8]:
image2="/content/drive/MyDrive/project/motorcycle race.jpg"
display_image_and_compare(image2,text_description)
best match for the image is : Motorcycle racing on track with the score of 27.8592
Output
In [9]:
image3="/content/drive/MyDrive/project/car parked.jpg"
display_image_and_compare(image3,text_description)
best match for the image is : Car parked near the building with the score of 25.4459
Output
In [10]:
image4="/content/drive/MyDrive/project/sitting people on cycle.jpg"
display_image_and_compare(image4,text_description)
best match for the image is : people sitting on the bicycles with the score of 22.5631
Output
In [11]:
image5="/content/drive/MyDrive/project/cycling during sunset.jpg"
display_image_and_compare(image5,text_description)
best match for the image is : A person riding a bicycle on the road with the score of 27.4925
Output
In [12]:
image6="/content/drive/MyDrive/project/cycling at forest.jpg"
display_image_and_compare(image6,text_description)
best match for the image is : some persons riding a bicyle at the forest with the score of 29.7607
Output
In [13]:
from IPython.display import HTML, display
import datetime

def notebook_signature(
    name="Sahil Umar",
    email="sahilumar20948s@gmail.com",
    linkedin="https://www.linkedin.com/in/sahil-umar-a48aa3328/",
    github="https://github.com/sahilumar123",
    contact="+91-8979361341",
    project="CLIP Image–Text Similarity",
    tool="SentenceTransformer + Matplotlib"
):
    today = datetime.date.today().strftime("%B %d, %Y")

    html = f"""
    <div style="
        background: linear-gradient(135deg, #fdfbfb, #ebedee);
        color: #111;
        padding: 25px 35px;
        border-radius: 18px;
        box-shadow: 0 6px 20px rgba(0,0,0,0.15);
        font-family: 'Poppins', 'Segoe UI', sans-serif;
        line-height: 1.7;
        text-align: center;
    ">
        <h2 style="
            margin-top: 0;
            font-size: 28px;
            font-weight: 700;
            color: #111;
        ">
            🤖 {project}
        </h2>

        <p style="font-size: 16px; color: #222;">
            <b>Author:</b> {name}<br>
            <b>Powered by:</b> <span style="color:#000;">{tool}</span><br>
            <b>Date:</b> <span style="color:#000;">{today}</span>
        </p>

        <p style="font-size: 15px; line-height: 1.8; color: #222;">
            📧 <b>Email:</b> <a href="mailto:{email}" style="color:#000; text-decoration:none;">{email}</a><br>
            💼 <b>LinkedIn:</b> <a href="{linkedin}" target="_blank" style="color:#000; text-decoration:none;">{linkedin}</a><br>
            💻 <b>GitHub:</b> <a href="{github}" target="_blank" style="color:#000; text-decoration:none;">{github}</a><br>
            📱 <b>Contact:</b> {contact}
    </div>
    """
    display(HTML(html))

notebook_signature()

🤖 CLIP Image–Text Similarity

Author: Sahil Umar
Powered by: SentenceTransformer + Matplotlib
Date: February 09, 2026

📧 Email: sahilumar20948s@gmail.com
💼 LinkedIn: https://www.linkedin.com/in/sahil-umar-a48aa3328/
💻 GitHub: https://github.com/sahilumar123
📱 Contact: +91-8979361341